<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/StudentsListDropexerciseThree.jsp" %>
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/CartimeListPage.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/backLayout.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/bombBox.css">
</head>
<style>
    select {
        width: 234px;
        height: 31px
    }

    .tr{
        background-color: #57a0ff;
        font-weight:700;
    }
    .tr td {
        font-size: 14px;
        color: #ffffff
    }

    .tr_td {
        height: 40px;
    }

    .tr_td td {
        border-bottom: 1px solid #ededed;
        text-align: center;
    }

    tr td:nth-child(1) {
        font-size: 14px;
        color: #cccccc
    }

    .date {
        border: 0;
        background: #ffffff;
        text-align: center;
    }

    .tr_td td:nth-child(1) {
        border-left: 1px solid #cccccc;
    }

    .tr_td td:nth-child(3) {
        border-right: 1px solid #cccccc;
    }

    .addTable.deleteTable:HOVER {
        cursor: pointer;
    }

    type[type='checkbox'] {
        width: 15px
    }

    .botton input {
        width: 230px;
    }

    .div_zilei {
        height: 30px
    }
    .div_input_hang {
        width: 100%;
        height: 40px;
    }
    .input_hang {
        float: left;
        width: 500px;
        height: 40px;
    }
</style>
<body style="background: #f5f5f5">
<div class="main">
    <div id="modal-overlay">

    </div>
    <div class="weizhi">
        练车管理>>科目三退练>>新增
    </div>
    <div class="div_body" style="box-shadow: 0 0 5px #cccccc;">
        <%--提示的隐藏标识--%>
        <input type="hidden" id="alertType" value="${alertType}">

        <div class="div_form">
            <form action="<%=path%>/DrivingSys/add_dropexercisethree" onsubmit="StopRepeat()" id="update_shar"
                  class="form" method="get">
                <div class="div_input_hang">
                    <div class="input_hang">
                        <span class="gn_name">驾校&nbsp;:&nbsp;</span>
                        <input disabled='disabled' type="text" name="name" value="${department}" readonly="readonly"
                               style="color: gray;"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">单据编号&nbsp;:&nbsp;</span>
                        <input type="text" name="fnumber" value="${fnumber}" style="color: gray;"
                               readonly="readonly"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">业务日期&nbsp;:&nbsp;</span>
                        <input type="text" name="fbizdate" id="fbizdate_bind" value="${fbizdate}"
                               onclick="WdatePicker({el:'fbizdate_bind',dateFmt:'yyyy-MM-dd'})"/>
                        <img onclick="WdatePicker({el:'fbizdate_bind',dateFmt:'yyyy-MM-dd'})"
                             src="<%=path%>/image/date.jpg" align="absmiddle" style="padding-left: 15px">
                    </div>
                </div>
                <div class="div_input_hang">
                    <div class="input_hang">
                        <span class="gn_name">参考信息&nbsp;:&nbsp;</span>
                        <input name="fdescription"/>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">单据状态&nbsp;:&nbsp;</span>
                        <select name="cfbillstate">
                            <option style="color: gray;" value="3">新增</option>
                        </select>
                    </div>
                    <div class="input_hang">
                        <span class="gn_name">练车时间&nbsp;:&nbsp;</span>
                        <input name="cflcsj" value="" style="color: gray;" class="is_click"
                               onclick="clicklcsj($(this))"/>
                        <input type="hidden" name="cflcsjid" class="cflcsjid" value="" style="color: gray;"/>
                    </div>
                </div>
                <div style="width: 20%; margin-left: 90px; float: left">已退学员</div>
                <div class="div_zilei" style="margin-left: 90px; float: left">
                    <div style="width: 40%;text-align: right;">
                        <img src="<%=path%>/image/insert2323.jpg" class="addTable">
                        <span style="padding-right: 20px;color:#57a0ff;font-weight:700;font-size: 14px" class="addTable">添加</span>
                        <img src="<%=path%>/image/delete212.png" class="deleteTable">
                        <span class="deleteTable" style="color: #57a0ff;font-weight:700;font-size: 14px" class="deleteTable">删除</span>
                    </div>
                </div>
                <div style="overflow:auto;min-height: 390px;max-height: 390px;width: 88%;margin-left: 90px;">
                    <table id="tablejl" width="55%" style=" min-height:50px;border-spacing:0;white-space:nowrap;">
                        <tr class="tr">
                            <td align="right"><%--<input type="checkbox" name="check" class="check" style="width: 15px;">--%>
                            </td>
                            <td width="30px">序号</td>
                            <td align="center">学员</td>
                            <td align="center">学员编号</td>
                            <td align="center">身份证号码</td>
                            <td align="center">教练</td>
                            <td align="center">几人一车</td>
                            <td align="center">练车天数</td>
                            <td align="center">退练原因</td>
                        </tr>
                        <tr>
                            <td align='right' width='20px'><input class='check2' type='checkbox' name='check2'
                                                                  style='width:15px'></td>
                            <td><input type="text" class="fseq" name="fseq" value="1" readonly="readonly"></td>
                            <td name='notcheck' align='center'><input style='width: 70px;' type='text'
                                                                      name='cfstudentName' value='' class="is_click"
                                                                      onclick='clickName($(this))'/><input type="hidden"
                                                                                                           class="cfstudentid"
                                                                                                           name="cfstudentid"/><%--学员id--%>
                            </td>
                            <td align='center'><input style='width: 120px;' readonly='readonly'
                                                      type='text' name='cfstudentno' value=''/>
                            </td>
                            <td align='center'><input style='width: 140px;' readonly='readonly' type='text'
                                                      name='cfidcardno' value=''/>
                            </td>
                            </td>
                            <td align='center'><input style='width: 70px;' readonly='readonly' type='text'
                                                      name='cfcoachName' value=''/>
                                <input type="hidden" name="cfcoachid"/><%--教练id--%>
                            </td>
                            <td name='notcheck' align='center'><input style='width: 70px;' type='text'
                                                                      name='cfcarpeoplenum' class="cfcarpeoplenum"
                                                                      value='0'/>
                            </td>
                            <td name='notcheck' align='center'><input style='width: 70px;' type='text'
                                                                      name='cflcts' class="cflcts" value='0'/></td>

                            <td name='notcheck' align='center'><input style='width: 150px;' type='text'
                                                                      name='cftlyy' value=''/></td>
                        </tr>
                    </table>
                </div>
                <div style="line-height:31px; margin-top: 80px; height: 31px; ">
                    <div class="botton">
                        <span class="gn_name">审核人&nbsp;:&nbsp;</span>
                        <input id="shename" disabled='disabled' type="text" name="ffivouchered"
                               value="${recordin.ffivouchered}">
                    </div>
                    <div class="botton">
                        <span class="gn_name">创建人&nbsp;:&nbsp;</span>
                        <input id="createname" disabled='disabled' type="text" name="createName"
                               value="${createName}">
                    </div>
                    <div>
                        <span class="gn_name">创建时间&nbsp;:&nbsp;</span>
                        <input id="updatetime" disabled='disabled' type="text" name="fcreatetime"
                               value="${recordin.fcreatetime}">
                    </div>
                </div>

                <div class="div_tj" style="margin-bottom: 200px;margin-left: 140px">
                    <div>
                        <input onclick="chcek()" class="input_submit bc" value="" type="button" style="margin-top: 0px;margin-right: 30px;">
                    </div>
                    <div>
                        <input type="button" class="input_back fh" value="" onclick="back()" style="margin-top: 0px;"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
<script type="text/javascript" src="<%=path%>/HoganJS/handlebars-v4.0.11.js"></script>
<script type="text/javascript">

    //选中的删除
    $(".deleteTable").click(function () {
        var tr_len = $("#tablejl tr").length;
        var s = '';
        $('input:checkbox[name=check2]').each(function (i) {

            if ($(this).is('.check2:checked')) {

                $(this).parent().parent().remove();
                s = '1';
                reorder()
            }
        })

        //判断是否选中
        if (s == null || s == '') {
            alert("请选择一条数据删除");
            return false;
        }
    })
    //设置全选功选
    $('.check').click(function () {
        if ($(this).attr("checked")) {
            $(".check2:checkbox").prop("checked", true)
        } else {
            $('.check2:checkbox').removeAttr('checked')
        }
    })
    //由于和input:checkbox冲突，在选择一次
    $("#tablejl tr td .check2:checkbox").live('click', function () {
        if ($(this).is('.check2:checked')) {
            $(this).removeAttr("checked");
        } else {
            $(this).attr("checked", ".check2:checked")
        }
    })
    //单击选中
    $("#tablejl tr td").live('click', function () {
        if ($(this).parent().find(".check2:checkbox").is(':checked')) {
            $(this).parent().find(".check2:checkbox").removeAttr("checked");
        } else {
            $(this).parent().find(".check2:checkbox").attr("checked", ":checked")
        }
    })

    //返回
    function back() {
        parent.closeSelectCard()
        //location = '<%=path%>/DrivingSys/queryDropexercisethree/look.action?state=first';
    }

    $('.addTable').click(function () {
        fseq = CalculateMaxNum('tablejl')
        var htmlperson = "<tr>" +
            "<td align='right' width='20px'><input class='check2' type='checkbox' name='check2' style='width:15px'></td>" +
            " <td><input type='text' class='fseq' name='fseq' value='" + fseq + "' readonly='readonly'></td>" +
            "<td name='notcheck' align='center'><input style='width: 70px;' type='text' class='is_click' name='cfstudentName' value='' onclick='clickName($(this))'/>" +
            "<input type='hidden' class='cfstudentid' name='cfstudentid'/></td> " +
            "<td align='center'><input style='width: 120px;'type='text' readonly='readonly' name='cfstudentno' value=''/></td> " +
            "<td align='center'><input style='width: 140px;' type='text' readonly='readonly' name='cfidcardno' value=''/> </td> " +
            "<td align='center'><input style='width: 70px;' type='text' readonly='readonly' name='cfcoachName' value=''/> " +
            "<input type='hidden' name='cfcoachid'/></td>" +
            " <td name='notcheck' align='center'><input style='width: 70px;' type='text'name='cfcarpeoplenum' class='cfcarpeoplenum' value='0'/> </td>" +
            " <td name='notcheck' align='center'><input style='width: 70px;' type='text'name='cflcts' class='cflcts' value='0'/></td>" +
            " <td name='notcheck' align='center'><input style='width: 150px;' type='text'name='cftlyy' value=''/></td>" +
            " </tr>";
        $("#tablejl").append(htmlperson)
    })

    function addStu() {
        fseq = CalculateMaxNum('tablejl')
        var htmlperson = "<tr>" +
            "<td align='right' width='20px'><input class='check2' type='checkbox' name='check2' style='width:15px'></td>" +
            " <td><input type='text' class='fseq' name='fseq' value='" + fseq + "' readonly='readonly'></td>" +
            "<td name='notcheck' align='center'><input style='width: 70px;' type='text' class='is_click' name='cfstudentName' value='' onclick='clickName($(this))'/>" +
            "<input type='hidden' class='cfstudentid' name='cfstudentid'/></td> " +
            "<td align='center'><input style='width: 120px;'type='text' readonly='readonly' name='cfstudentno' value=''/></td> " +
            "<td align='center'><input style='width: 140px;' type='text' readonly='readonly' name='cfidcardno' value=''/> </td> " +
            "<td align='center'><input style='width: 70px;' type='text' readonly='readonly' name='cfcoachName' value=''/> " +
            "<input type='hidden' name='cfcoachid'/></td>" +
            " <td name='notcheck' align='center'><input style='width: 70px;' type='text'name='cfcarpeoplenum' class='cfcarpeoplenum' value='0'/> </td>" +
            " <td name='notcheck' align='center'><input style='width: 70px;' type='text'name='cflcts' class='cflcts' value='0'/></td>" +
            " <td name='notcheck' align='center'><input style='width: 150px;' type='text'name='cftlyy' value=''/></td>" +
            " </tr>";
        $("#tablejl").append(htmlperson)
    }

    //改变复选框的值
    function chcek() {
        if ($('#update_shar').find("tr").length == 1) {
            alert('请至少选择一条数据！')
            return false;
        }
        $('#update_shar').submit()

    }

    /* 关闭弹出框    */
    $('.btn').click(function () {
        $('#modal-overlay').css('visibility', 'hidden')
        $('.modal-data').css('visibility', 'hidden')
        $('.modal-data1').css('visibility', 'hidden')
        $('.modal-data2').css('visibility', 'hidden')
        $('.modal-data3').css('visibility', 'hidden')
        $('.data-checkbox:checkbox').removeAttr('checked');
        $('.data1-checkbox:checkbox').removeAttr('checked');
        $('.data2-checkbox:checkbox').removeAttr('checked');
        $('.data3-checkbox:checkbox').removeAttr('checked');
        $('.page').hide();
    })

    //弹出练车时间的信息框
    function clicklcsj(e) {
        $('#modal-overlay').css('visibility', 'visible')
        $('.modal-data3').css('visibility', 'visible')
        $('.data3-checkbox:checkbox').removeAttr('checked');
        $('.page').show();
        _this = e;
    }

    //弹出模式框学生信息
    function clickName(e) {
        $('#modal-overlay').css('visibility', 'visible')
        $('.modal-data').css('visibility', 'visible')
        $('.data-checkbox:checkbox').removeAttr('checked');
        _this = e.parent().parent();
        myname = $('.name1').val();
        cflcsjid = $('.cflcsjid').val();
        index = 1
        $('#studebntList').html("<div class='loading'></div>");
        $.ajax({
            url: '<%=path2%>/DrivingSys/getPageDropexercise',
            type: "post",
            data: {
                'pindex': '0',
                'name': myname,
                'cflcsjid': cflcsjid,
                'state': '3'
            },
            dataType: "json",
            success: function (res) {
                $('#studebntList').html(myTemplate(res));
                $('#totalPage').val(res.pb);
            },
            error: function () {
                alert('Error');
            }
        });
    }


    //把选中的学生信息名称填充到输入框中
    $('.subtn').click(function () {
        var spCodesTemp = "";
        $('input:checkbox[name=student]:checked').each(function (i) {
            spCodesTemp = $(this).val();
        });

        var eachcount = 0;
        if (spCodesTemp == "") {
            alert('请选择学生信息！');
            return false;
        }
        $.ajax({
            url: '<%=path%>/DrivingSys/selStudentsBySharecartwo',
            type: "post",
            data: {
                'id': spCodesTemp,
                'state': '3'
            },
            dataType: "json",
            success: function (res) {

                res = res[0];

                $('.cfstudentid').each(function () {


                    if ($(this).val() == res.fid) {
                        alert('学员' + res.xyname + '信息重复！');
                        return false;
                    }

                    eachcount++

                    if (eachcount >= $(".cfstudentid").length) {
                        addData(res)
                    }

                })


            },
            error: function () {
                alert('Error');
            }
        });

    });

    function addData(res) {
        _this.children().children('input[name=cfstudentName]').val(res.xyname);
        _this.children().children('input[name=cfstudentid]').val(res.fid);
        _this.children().children('input[name=cfstudentno]').val(res.cfstudentno);
        _this.children().children('input[name=cfidcardno]').val(res.cfidcardno);
        _this.children().children('input[name=cfmobile]').val(res.cfmobile);
        _this.children().children('input[name=cfphone]').val(res.cfphone);
        _this.children().children('input[name=cfcoachName]').val(res.jlname);
        _this.children().children('input[name=cfcoachid]').val(res.cfcoachid);
        $('#modal-overlay').css('visibility', 'hidden')
        $('.modal-data').css('visibility', 'hidden')
    }

    $(document).on('keyup', '.cfcarpeoplenum', function (event) {
        //最后一位是小数点的话，移除
        var $amountInput = $(this);
        //响应鼠标事件，允许左右方向键移动
        event = window.event || event;
        if (event.keyCode == 37 | event.keyCode == 39) {
            return;
        }
        var clazz = $(this).prop("class")
        //获取输入框的值
        var value = $(this).val();
        //判断负数是否在第一位
        if (value.substring(0, 1) == '-') {

        }
        if (value.length == 0) {
            $(this).val("0")
        }
        if (value.lastIndexOf('0') == 0) {
            $(this).val(value.substring(1, value.length))
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //判断负数不是在第一位，替换
        if (value.lastIndexOf('-') >= 0) {
            $(this).val("0")
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //先把非数字的都替换掉，除了数字和.
        $amountInput.val($amountInput.val().replace(/[^\-?\d]/g, "").//只允许一个小数点
        replace(/^\./g, "").replace(/\.{2,}/g, ".").//只能输入小数点后两位
        replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
        if ($(this).val() == "") {
            $(this).val(0)
        }
    });

    $(document).on('keyup', '.cflcts', function (event) {
        //最后一位是小数点的话，移除
        var $amountInput = $(this);
        //响应鼠标事件，允许左右方向键移动
        event = window.event || event;
        if (event.keyCode == 37 | event.keyCode == 39) {
            return;
        }
        var clazz = $(this).prop("class")
        //获取输入框的值
        var value = $(this).val();
        //判断负数是否在第一位
        if (value.substring(0, 1) == '-') {

        }
        if (value.length == 0) {
            $(this).val("0")
        }
        if (value.lastIndexOf('0') == 0) {
            $(this).val(value.substring(1, value.length))
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //判断负数不是在第一位，替换
        if (value.lastIndexOf('-') >= 0) {
            $(this).val("0")
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //先把非数字的都替换掉，除了数字和.
        $amountInput.val($amountInput.val().replace(/[^\-?\d]/g, "").//只允许一个小数点
        replace(/^\./g, "").replace(/\.{2,}/g, ".").//只能输入小数点后两位
        replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
        if ($(this).val() == "") {
            $(this).val(0)
        }
    });

</script>
<%@ include file="/WEB-INF/JSP/ajax.jsp" %>
</html>